using System;
using System.Threading;

namespace EpisodeWizard.CoreUI
{

	/// <summary>
	/// Summary description for ThreadedInit.
	/// </summary>
	public static class ThreadHelpers
	{
		public static void StartThreadedAction(Core.ThreadedAction Action, bool HandlesPercents)
		{
			CoreUI.FrmThreadProgress Display = new CoreUI.FrmThreadProgress();

			if (HandlesPercents)
			{
				Display.ProgressStyle = CoreUI.FrmThreadProgress.EProgressStyle.Percentage;
			}
			else
			{
				Display.ProgressStyle = CoreUI.FrmThreadProgress.EProgressStyle.Continuous;
			}

			// From the thread to the UI
			Action.Start += new Core.ThreadedAction.StartHandler(Display.OnStart);
			Action.Progress += new Core.ThreadedAction.ProgressHandler(Display.OnProgress);
			Action.End += new Core.ThreadedAction.EndHandler(Display.OnEnd);

			// From the UI to the thread
			Display.RequestCancel += new CoreUI.FrmThreadProgress.CancelHandler(Action.OnCancel);

			Action.StartAction();
			Display.ShowDialog();
		}
	}
}

